package org.example.domain;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NegativeOrZero;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import javax.validation.constraints.Positive;
import java.util.Date;
import java.util.List;

@Data
@TableName("discussion")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Discussion {

    public interface save{};
    public interface search{};
    public interface update{};

    @TableId("id")
    @Null(message = "讨论ID必须为空",groups = {save.class,search.class})
    @NotNull(message = "讨论ID不能为空",groups = {update.class})
    private Integer discussionId;
    @NotNull(message = "讨论主题不能为空",groups = {save.class})
    private String title;
    @NotNull(message = "讨论类型不能为空",groups = {save.class})
    private String type;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone="GMT+8")
    @Null(message = "讨论创建时间必须为空",groups = {save.class,search.class,update.class})
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "create_time",fill = FieldFill.INSERT)
    private Date createTime;
    @NegativeOrZero(message = "讨论点击量必须为0",groups = {save.class,search.class,update.class})
    private int click;
    @NegativeOrZero(message = "讨论点赞数必须为0",groups = {save.class,search.class,update.class})
    private int likes;
    @Positive(message = "讨论创建者不能为空",groups = {save.class})
    @NegativeOrZero(message = "讨论创建者必须为空",groups = {update.class})
    private int userId;
    @TableField(exist = false)
    @Null(message = "讨论详细内容必须为空",groups = {search.class})
    @NotNull(message = "讨论内容不能为空",groups = {save.class})
    private String content;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone="GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "update_time",fill = FieldFill.UPDATE)
    private Date updateTime;

    @TableField(exist = false)
    private String userIcon;
    @TableField(exist = false)
    @NegativeOrZero(message = "评论数量必须为空",groups = {save.class})
    private int commentNumber;
}
